package com.sitanyun.merchant.guide.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.bean.TrajeBean;

import java.util.List;

/**
 * Created by jzl
 * on 2022/1/26.
 * 轨迹子列表
 */
public class TrajeListsAdapter extends BaseAdapter {
    private Context context;
    private List<TrajeBean.DataBean.ListBean> tralists;

    public TrajeListsAdapter(Context context, List<TrajeBean.DataBean.ListBean> tralists) {
        this.context = context;
        this.tralists = tralists;
    }

    @Override
    public int getCount() {
        return tralists.size();
    }

    @Override
    public Object getItem(int position) {
        return tralists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.tra_lists,null);
        ImageView enterimg= convertView.findViewById(R.id.enter_img);
        TextView entershop= convertView.findViewById(R.id.enter_shop);

        TextView entertimes= convertView.findViewById(R.id.enter_times);

        TextView times= convertView.findViewById(R.id.times);
        times.setText(tralists.get(position).getStartTime().substring(11,tralists.get(position).getStartTime().length()));
        //浏览
        if (tralists.get(position).getBehavior().equals("BROWSE")){
           Glide.with(context).load(R.mipmap.looks).into(enterimg);
            entershop.setText("查看"+tralists.get(position).getSceneName());
            entertimes.setVisibility(View.GONE);
            //留言
       }else if (tralists.get(position).getBehavior().equals("MESSAGE")){
            Glide.with(context).load(R.mipmap.xxs).into(enterimg);
            entershop.setText("发起留言");
            entertimes.setVisibility(View.GONE);
        }else if (tralists.get(position).getBehavior().equals("CALL")){
            Glide.with(context).load(R.mipmap.cphones).into(enterimg);
            entershop.setText("要求回电");
            entertimes.setVisibility(View.GONE);
        }else if (tralists.get(position).getBehavior().equals("MEETING")){
            Glide.with(context).load(R.mipmap.tps).into(enterimg);
            entershop.setText("同屏讲解");
            entertimes.setVisibility(View.VISIBLE);
            int intTime= tralists.get(position).getDuration();
            int h=intTime/3600;
            int m=(intTime%3600)/60;
            int s=(intTime%3600)%60;
            if (h==0){
                entertimes.setText(""+m+"分"+s+"秒");
            }else {
                entertimes.setText(""+h+"时"+m+"分钟");
            }

        }else if (tralists.get(position).getBehavior().equals("BROWSE_END")){
            entershop.setText("退出");
            entertimes.setVisibility(View.GONE);
            Glide.with(context).load(R.mipmap.outs).into(enterimg);
        }else if (tralists.get(position).getBehavior().equals("SWITCH")){
            entershop.setText("观看"+tralists.get(position).getSubSceneName());
            entertimes.setVisibility(View.GONE);
            Glide.with(context).load(R.mipmap.swich).into(enterimg);
        }

        return convertView;
    }
}
